#!/usr/bin/python
# -*- coding:utf-8 -*-
# @author  : micah
# @time    : 2023/9/7 23:52
# @function: the script is used to do something.
# @version :
from pymongo import MongoClient

# 连接MongoDB数据库
client = MongoClient(host='127.0.0.1', port=27017)
collection = client['mongo_data_info']['test_python']


# 插入用户信息
user_data = {
    '姓名': '张三',
    '年龄': 25,
    '住址': '北京市',
    '爱好': '篮球'
}
collection.insert_one(user_data)

# 修改用户的爱好
collection.update_one({'姓名': '张三'}, {'$set': {'爱好': '足球'}})

# 查询用户信息
user_info = collection.find_one({'姓名': '张三'})
print(user_info)

# 删除用户信息
collection.delete_one({'姓名': '张三'})